﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Service
{
    public class CustomSqlCache<T> where T : class
    {
        private static string QuerySql = string.Empty;

        static CustomSqlCache()
        {
            Type type = typeof(T);
            QuerySql= $"SELECT {string.Join(",", type.GetProperties().Select(c=>$"[{c.Name}]"))} FROM {$"dbo.[{type.Name}]"}";
        }

        public static string GetQuerySql() => QuerySql;

        public static string GetFindByIdSql(int Id) => $"{QuerySql} WHERE ID={Id}";
    }

    public class CustomMySqlCache<T> where T : class
    {
        private static string QueryMySql = string.Empty;

        static CustomMySqlCache()
        {
            Type type = typeof(T);
            QueryMySql = $"SELECT {string.Join(",", type.GetProperties().Select(c => $"{c.Name}"))} FROM {$"{type.Name}"}";
        }

        public static string GetQuerySql() => QueryMySql;

        public static string GetFindByIdSql(int Id) => $"{QueryMySql} WHERE ID={Id}";

    }
}
